package com.shigen.shop.config;

import com.google.code.kaptcha.Constants;
import com.google.code.kaptcha.impl.DefaultKaptcha;
import com.google.code.kaptcha.util.Config;
import java.util.Properties;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

/**
 * kaptcha配置类
 *
 * @author shigenfu
 * @date 2022/7/24 3:52 下午
 */
@Configuration
public class CaptchaConfig {

  @Bean
  @Qualifier("captchaProducer")
  public DefaultKaptcha kaptcha() {
    DefaultKaptcha kaptcha = new DefaultKaptcha();
    Properties properties = new Properties();
    //验证码个数
    properties.setProperty(Constants.KAPTCHA_TEXTPRODUCER_CHAR_LENGTH, "4");
    //字体间隔
    properties.setProperty(Constants.KAPTCHA_TEXTPRODUCER_CHAR_SPACE, "8");
    //干扰线颜色
    properties.setProperty(Constants.KAPTCHA_NOISE_COLOR, "red");
    //干扰实现类
    properties.setProperty(Constants.KAPTCHA_NOISE_IMPL, "com.google.code.kaptcha.impl.DefaultNoise");
    //图片样式
    properties.setProperty(Constants.KAPTCHA_OBSCURIFICATOR_IMPL, "com.google.code.kaptcha.impl.WaterRipple");
    //文字来源
    properties.setProperty(Constants.KAPTCHA_TEXTPRODUCER_CHAR_STRING, "0123456789qwertyuiopasdfghjklzxcvbnmQWERTYUIOPLKJHGFDSAZXCVBNM");
    Config config = new Config(properties);
    kaptcha.setConfig(config);
    return kaptcha;
  }
}
